unit fpSettings;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  System.ImageList,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.ComCtrls,
  Vcl.StdCtrls,
  Vcl.Samples.Spin,
  Vcl.ExtCtrls,
  Vcl.ImgList,
  Vcl.Grids,
  Vcl.Outline,
  Vcl.Samples.DirOutln,
  Vcl.ColorGrd,
  Vcl.Samples.Gauges,
  Vcl.CheckLst,
  Vcl.WinXCtrls,
  Vcl.NumberBox,

  fpForm;

type
  TfrmSettings = class(TFormP)
    PanelBottom: TPanel;
    ButtonOK: TButton;
    PanelMiddle: TPanel;
    PageControl: TPageControl;
    tsInterface: TTabSheet;
    LabelProgram: TLabel;
    LabelData: TLabel;
    PanelExePath: TPanel;
    cbDataPath: TComboBox;
    ButtonBrowsePathData: TButton;
    CheckBoxLoadProject: TCheckBox;
    CheckBoxSaveProject: TCheckBox;
    tsDisplay: TTabSheet;
    LabelBackground: TLabel;
    CheckBoxAxes: TCheckBox;
    PanelBackground: TPanel;
    chbCoordinates: TCheckBox;
    chbTwoSideLighting: TCheckBox;
    tsDatatime: TTabSheet;
    PanelScale: TPanel;
    lblScaleX: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    tsMaterial: TTabSheet;
    ListView: TListView;
    ButtonModifyMat: TButton;
    tvSettings: TTreeView;
    PanelTop: TPanel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    ImageList: TImageList;
    tsGalaxy: TTabSheet;
    tsStars: TTabSheet;
    tsPlanets: TTabSheet;
    LabelRg: TLabel;
    lbExoplanets: TListBox;
    ComboBox1: TComboBox;
    rgLanguage: TRadioGroup;
    Memo1: TMemo;
    chlbStarClasses: TCheckListBox;
    cbSplashStart: TCheckBox;
    tsGeneral: TTabSheet;
    tsFlights: TTabSheet;
    gbxCoordinateSys: TGroupBox;
    rgrSystem: TRadioGroup;
    rgUnits: TRadioGroup;
    PanelTitle: TPanel;
    LabelA: TLabel;
    LabelB: TLabel;
    LabelDistance: TLabel;
    LabelVelocity: TLabel;
    LabelFlightTime: TLabel;
    SearchBoxA: TSearchBox;
    trbVelocity: TTrackBar;
    stFlightTime: TStaticText;
    SearchBoxB: TSearchBox;
    EditDistance: TEdit;
    gbFindPath: TGroupBox;
    chbOnDelaunay: TCheckBox;
    gbStarColors: TGroupBox;
    ShapeM: TShape;
    ShapeK: TShape;
    ShapeG: TShape;
    ShapeF: TShape;
    ShapeA: TShape;
    ShapeO: TShape;
    ShapeB: TShape;
    Label4: TLabel;
    Label3: TLabel;
    clbStarColors: TCheckListBox;
    ListBox2: TListBox;
    stColor: TStaticText;
    ColorGrid1: TColorGrid;
    RadioGroup1: TRadioGroup;
    chbSysTime: TCheckBox;
    SpinEditPrecision: TSpinEdit;
    LabelPrecision: TLabel;
    rgPathway: TRadioGroup;
    chbOnVoronoi: TCheckBox;
    tsMap: TTabSheet;
    rgConstellations: TRadioGroup;
    chbAxis: TCheckBox;
    chbGrid: TCheckBox;
    Label_ly: TLabel;
    Label_year: TLabel;
    Label_kms: TLabel;
    nbRg: TNumberBox;
    Label5: TLabel;
    nbRc: TNumberBox;
    Label6: TLabel;
    NumberBox1: TNumberBox;
    Label7: TLabel;
    nbNs: TNumberBox;
    chbRotate: TCheckBox;
    procedure tvSettingsClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure trbVelocityChange(Sender: TObject);
    procedure rgConstellationsClick(Sender: TObject);
    procedure ButtonOKClick(Sender: TObject);
  private
    //
    Node: TTreeNode;
    Nodes: TTreeNodes;
  public
    //
  end;

var
  frmSettings: TfrmSettings;

//================================================
implementation

{$R *.dfm}

uses
  fpAstroViewer;

procedure TfrmSettings.ButtonOKClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmSettings.FormCreate(Sender: TObject);
begin
  // Default classes for terrain planets
	chlbStarClasses.Checked[0] := False;
 	chlbStarClasses.Checked[1] := False;
 	chlbStarClasses.Checked[2] := False;
	chlbStarClasses.Checked[3] := True;
 	chlbStarClasses.Checked[4] := True;
 	chlbStarClasses.Checked[5] := True;
 	chlbStarClasses.Checked[6] := True;

  tvSettings.Select(tvSettings.Items[2]);
  tvSettings.Items[2].Selected := True;
  tvSettings.Items[2].Focused := True;
  tvSettingsClick(Sender);

  trbVelocityChange(Self);
end;

procedure TfrmSettings.FormShow(Sender: TObject);
var
  I: Integer;
begin
//  create new nodes
//  Nodes := TTreeNodes.Create (tvSettings);
//  Node := TTreeNode.Create (Nodes);
//  Node := nil;

  for I := 0 to tvSettings.Items.Count - 1 do
  begin
    tvSettings.Items[i].ImageIndex := 0;
    tvSettings.Items[i].SelectedIndex := 1;
  end;
  tvSettings.FullExpand;
  tvSettings.Items[9].DropHighlighted := True;
end;

//------------------------------------------------------------------
procedure TfrmSettings.rgConstellationsClick(Sender: TObject);
begin
  CurrDir := DataDir + 'constellation\';
  SetCurrentDir(CurrDir);

  frmAstroViewer.ConstLines.Nodes.Clear;
  frmAstroViewer.ConstBounds.Nodes.Clear;
  case rgConstellations.ItemIndex of
    0: begin
         // none
         frmAstroViewer.SkyDome.ClearStructureChanged;
       end;
    1: begin
         // Lines
         frmAstroViewer.LoadConstLines(CurrDir);
       end;
    2: begin
         // Borders
         frmAstroViewer.LoadConstBorders(CurrDir);
       end;
  end;
  CurrDir := DataDir + 'map\';
  SetCurrentDir(CurrDir);

end;

procedure TfrmSettings.trbVelocityChange(Sender: TObject);
var
  DistanceInYears: Single;
  Ratio, FlightTime: Extended;

begin
  DistanceInYears := StrToFloat(EditDistance.Text);
  Ratio := trbVelocity.Position/299792;
  FlightTime := DistanceInYears/Ratio;

  stFlightTime.Caption := FloatToStrF(FlightTime, ffFixed, 20, 1);

end;

procedure TfrmSettings.tvSettingsClick(Sender: TObject);
begin
  tvSettings.Items[9].DropHighlighted := False;

  case tvSettings.Selected.Index of
     0: PageControl.ActivePage := tsGeneral;
     1: PageControl.ActivePage := tsInterface;
     2: PageControl.ActivePage := tsDisplay;
     3: PageControl.ActivePage := tsDatatime;
     4: PageControl.ActivePage := tsMaterial;
     5: PageControl.ActivePage := tsPlanets;
     6: PageControl.ActivePage := tsStars;
     7: PageControl.ActivePage := tsGalaxy;
     8: PageControl.ActivePage := tsFlights;
     9: PageControl.ActivePage := tsMap;
  end;
end;

end.
